import type { ShapeType } from '@/interface';
import { DEFAULTLAYER } from '@/constant';

interface PropsType {
  startX?: number;
  startY?: number;
}

class StraightLine implements ShapeType {
  private type: string;
  private layer: number;
  startX: number;
  startY: number;
  endX: number;
  endY: number;
  constructor(props?: PropsType) {
    this.type = 'straightline';
    this.layer = DEFAULTLAYER;
    this.startX = props?.startX || 0;
    this.startY = props?.startY || 0;
    this.endX = this.startX;
    this.endY = this.startY;
  }

  getType(): string {
    return this.type;
  }

  getLayer(): number {
    return this.layer;
  }

  setEnd(x: number, y: number): void {
    this.endX = x;
    this.endY = y;
  }

  draw(ctx: CanvasRenderingContext2D): void {
    ctx.beginPath();
    ctx.moveTo(this.startX, this.startY);
    ctx.lineTo(this.endX, this.endY);
    ctx.stroke();
  }
}

export default StraightLine;
